<?php
/**
 * 
 * @authors Gary_zhou
 * @date    2016-06-29 11:39:15
 * @version v1.0.0
 * 
 * 转换成JS
 * 
 * 
 */
require ('./xml2array.php');
// $share_xml = new DOMDocument();
// $share_xml->load('../db/wxShare.xml');

// $xml_dom = $share_xml->documentElement;

// $data = array();
// $temp = array();

// foreach ($xml_dom->childNodes as $k => $v) {
// 	$temp = [];
// 	if ($v->nodeType == 1) {
// 		foreach ($v->childNodes as $k1 => $v1) {
// 			if ($v1->nodeType == 1) {
// 				$temp[] = '"'.$v1->nodeName.'"'.'\|'.'"'.$v1->nodeValue.'"';
// 			}
// 		}

// 		$data[] = $temp;
// 	}
// }

//var_dump($data);

$share_js = fopen("share.js", "w") or die("Unable to open file!");
$share_start = "var xmWxShare = { \n";

$share_body_start = "";
$share_body_body = "";
$share_body_end = "";

$share_body = "";

foreach ($data as $k2 => $v2) {

	$share_body_start = $k2." : { \n";
	$share_body_body = "";
	foreach ($v2 as $k3 => $v3) {
		$share_body_body .= explode('\|',$v3)[0].":".explode('\|',$v3)[1].",\n";
	}
	$share_body_end = "},\n";

	$share_body .= $share_body_start.$share_body_body.$share_body_end;
}

$share_end = "}\n";


$share = $share_start.$share_body.$share_end;

fwrite($share_js, $share);
fclose($share_js);

echo json_encode(array('code' => 0));
